/*
 * <p>Copyright® 2009-2022 东软 IT 实训中心版权所有。</p>
 */

package com.max.back.doctor.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.max.back.entity.Patient;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

/**
* @description 
* 
* <p>
* <code>PatientDao</code>
*
* </p>
* 
* @see 
* @author 辛凤文 forward.seen@foxmail.com
* @version 1.0 
* @time 2022/7/21 23:18 
*/
@Repository
public interface PatientDao extends BaseMapper<Patient> {
    /**
     * 根据挂号ID查找负责接待医生的ID
     * @return
     */
    @Select({
          "SELECT\n" +
                  "\tp.ID ID\n" +
                  "FROM \n" +
                  "\tPATIENT p \n" +
                  "WHERE \n" +
                  "\tp.IDENT_ID = (\n" +
                  "\t\tSELECT\n" +
                  "\t\t\tr.IDENT_ID IDENT_ID \n" +
                  "\t\tFROM \n" +
                  "\t\t\tREGISTRATION r \n" +
                  "\t\tWHERE \n" +
                  "\t\t\tr.ID = #{registrationId}\n" +
                  "\t\tAND\n" +
                  "\t\t\tr.DELETED = 0)\n" +
                  "\tAND\n" +
                  "\t\tp.DELETED = 0"
    })
    Patient selectIdByRegistrationId(@Param("registrationId") String registrationId);

    /**
     * 根据病历ID查询病人姓名和身份证号
     * @param patientHistoryId
     * @return
     */
    @Select({
            "SELECT name,IDENT_ID FROM PATIENT WHERE ID = (SELECT PATIENT_ID " +
                    "FROM PATIENT_HISTORY WHERE id = #{patientHistoryId})"
    })
    Patient selectNameAndIdentByPatientHistoryId(@Param("patientHistoryId") String patientHistoryId);
}